package com.fellw.mango.real_person.authentication.api;


import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

/**
 * ID real name authentication OCR VerifiedO result
 *
 * @author fate
 * @version 1.0.0
 * @since 1.0.0
 */
public interface IDVerifiedOCRResult {
    /**
     * ID number
     */
    String getPersonalNumber();

    /**
     * Full name
     */
    String getPersonalName();

    String getAddress();

    /**
     * validity period
     */
    Date getPersonalValidityPeriod();


    /**
     * See {@link  IDVerifiedOCRResult#getPersonalValidityPeriod()}
     *
     * @return Visualization
     */
    default String getPersonalValidityPeriodVisualization() {
        if (Objects.isNull(getPersonalValidityPeriod())) {
            return null;
        }
        return new SimpleDateFormat("yyyy-MM-dd").format(getPersonalValidityPeriod());
    }

    interface Setting {
        /**
         * ID number
         */
        void setPersonalNumber(String value);

        /**
         * Full name
         */
        void setPersonalName(String value);

        /**
         * 地址
         */
        void setAddress(String value);

        /**
         * validity period
         */
        void setPersonalValidityPeriod(Date value);


        default void of(IDVerifiedOCRResult model) {
            setPersonalName(model.getPersonalName());
            setPersonalNumber(model.getPersonalNumber());
            setPersonalValidityPeriod(model.getPersonalValidityPeriod());
            setAddress(model.getAddress());
        }
    }

    /**
     * ID real name authentication OCR VerifiedO result data
     *
     * @author fate
     * @version 1.0.0
     * @since 1.0.0
     */
    @Data
    @Builder
    @Schema(name = "IDVerifiedOCRResultData")
    @AllArgsConstructor
    @NoArgsConstructor
    class D implements IDVerifiedOCRResult, Setting {
        /**
         * ID number
         */
        private String personalNumber;

        /**
         * Full name
         */
        private String personalName;

        /**
         * 身份证地址
         */
        private String address;

        /**
         * validity period
         */
        private Date personalValidityPeriod;
    }

}
